<template>
  <div>

    <el-select @change="checkUser" v-model="value" placeholder="请选择用户查询待办">
      <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>


    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          prop="task.id"
          label="任务实例Id">
      </el-table-column>

      <el-table-column
          prop="task.name"
          label="任务名称">
      </el-table-column>

      <el-table-column
          prop="task.assignee"
          label="负责人">
      </el-table-column>
      <el-table-column
          prop="task.cause"
          label="请假原因">
      </el-table-column>
      <el-table-column
          prop="task.holiday"
          label="请假天数">
      </el-table-column>
      <el-table-column
          prop="historicProcessInstance.processInstanceId"
          label="历史流程实例id">
      </el-table-column>
      <el-table-column
          prop="historicProcessInstance.businessKey"
          label="流程实例绑定的业务key">
      </el-table-column>
      <el-table-column
          prop="task.applyUser"
          label="申请人">
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">

          <el-button
              size="mini"
              type="danger"
              @click="leaderApprove(scope.row)">同意
          </el-button>

          <el-button
              size="mini"
              type="danger"
              @click="leaderReject(scope.row)">驳回
          </el-button>

          <el-button size="mini" type="primary" @click="rwzz(scope.row)">任务追踪</el-button>

        </template>
      </el-table-column>


    </el-table>
  </div>
</template>

<script>
export default {
  name: "TaskList",
  data(){
    return{
      tableData:[],
      options: [{
        value: 'zhangsan',
        label: 'zhangsan'
      }, {
        value: 'lisi',
        label: 'lisi'
      }, {
        value: 'xiaoming',
        label: 'xiaoming'
      }],
      value: 'zhangsan'
    }
  },
  methods:{
    init(){
      this.axios.post("http://127.0.0.1:8083/queryTaskByAssignee", {"username":this.value}).then(resp=>{
        console.log(resp.data)
        this.tableData=resp.data
      })
    },
    checkUser(){
      this.init()
    },
    //同意
    leaderApprove(row){
      this.axios.post("http://127.0.0.1:8083/doTask", {"taskId":row.task.id,"approve":true,"username":this.value}).then(resp=>{
        if(resp.data=="success"){
          alert(resp.data)
          this.init();
        }
      })
    },
    //驳回
    leaderReject(row){
      this.axios.post("http://127.0.0.1:8083/doTask", {"taskId":row.task.id,"approve":false,"username":this.value}).then(resp=>{
        if(resp.data=="success"){
          alert(resp.data)
          this.init();
        }
      })
    },
    rwzz(row){
      //新打开一个窗口,让这个窗口显示一张图片,并且这张图片显示当前的进度
      window.open("http://127.0.0.1:8083/viewTask?processInstanceId="+row.historicProcessInstance.processInstanceId);
    }
  }
  ,
  mounted() {
    this.init()
  }
}
</script>

<style scoped>

</style>